package lc;

public class lc91 {
    public static void main(String[] args) {
        numDecodings("12");
    }
    public static int numDecodings(String s) {
        if(s.charAt(0) == 0) return 0;
        int n = s.length();
        int[] dp = new int[n];
        dp[0] = 1;
        if(n == 1) return 1;
        if(s.charAt(1) == '0'){
            if(s.charAt(0) == 1 || s.charAt(0) == 2) dp[1] = 1;
            else return 0;
        }else if(s.charAt(0) == '1' || (s.charAt(0) == '2' && s.charAt(1) < '7')){
            dp[1] = 2;
        } else dp[1] = 1;
        for(int i = 2; i < n; ++i){
            if(s.charAt(i) == '0'){
                if(s.charAt(i - 1) == 1 || s.charAt(i - 1) == 2) dp[i] = dp[i - 2];
                else return 0;
            }else if(s.charAt(i - 1) == '1' || (s.charAt(i - 1) == '2' && s.charAt(i) < '7')){
                dp[i] = dp[i - 1] + dp[i - 2];
            } else dp[i] = dp[i - 2];
        }
        return dp[n - 1];
    }
}
